<template>
	<view class="page">
		<pageTxt>
			<!--  v-model="dataList" @query="queryList" -->
			<z-paging ref="paging" refresher-only @onRefresh="onRefresh" :paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<u-navbar title="预算详情" :autoBack="true" :fixed="false"></u-navbar>
					<view class="tab-box">
						<u-tabs
							:current="tabIndex"
							@click="tabClickFunc"
							:list="tablist"
							inactiveStyle="color: #919092;"
							activeStyle="color: #3B75FF;"
							lineColor="#3B75FF"
						></u-tabs>
					</view>
				</template>
				<!-- 内容 -->
				<view class="detail-content-box" v-if="dataObj">
					<u-empty
						v-if="!$fieldShowFunc('41-xmxx') && !$fieldShowFunc('41-bjxx')"
						marginTop="300rpx"
						icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png"
						text=" "
					></u-empty>
					<template v-if="tabIndex == 0">
						<view class="item-box" v-if="$fieldShowFunc('41-xmxx')">
							<view class="title">项目信息</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_xmmc')">
								<text class="txt">项目名称</text>
								<view class="content">
									{{ dataObj.project_name || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_xmbh')">
								<text class="txt">项目编号</text>
								<view class="content">
									<text class="txt-btn" @click="navToProjectFunc">
										{{ dataObj.project_number || '--' }}
									</text>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_xmpp')">
								<text class="txt">项目品牌</text>
								<view class="content">
									{{ dataObj.brand_name || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_xmlx')">
								<text class="txt">项目类型</text>
								<view class="content">
									{{ dataObj.store_type_name || '--' }}
								</view>
							</view>
						</view>
						<view class="item-box" v-if="$fieldShowFunc('41-bjxx')">
							<view class="title">报价信息</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_bjbh')">
								<text class="txt">报价编号</text>
								<view class="content">
									{{ dataObj.quotation.quotation_number || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_zjy')">
								<text class="txt">造价员</text>
								<view class="content">
									{{ dataObj.cost_estimator_name || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_bjdzt')">
								<text class="txt">报价单状态</text>
								<view class="content">
									<template v-if="dataObj.quotation_status == 10">待报价</template>
									<template v-if="dataObj.quotation_status == 20">待工程经理审核</template>
									<template v-if="dataObj.quotation_status == 25">工程经理审核拒绝</template>
									<template v-if="dataObj.quotation_status == 30">待造价主管审核</template>
									<template v-if="dataObj.quotation_status == 35">造价主管审核拒绝</template>
									<template v-if="dataObj.quotation_status == 40">待签约</template>
									<template v-if="dataObj.quotation_status == 45">客户经理退回报价单</template>
									<template v-if="dataObj.quotation_status == 50">已签约</template>
									<template v-if="dataObj.quotation_status == 60">已取消</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_sqbjsj')">
								<text class="txt">申请报价时间</text>
								<view class="content">
									{{ dataObj.apply_quotation_date || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_zzbjsj')">
								<text class="txt">最终报价时间</text>
								<view class="content">
									{{ dataObj.quotation_date || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_sjdsx')">
								<text class="txt">报价单时效</text>
								<view class="content">
									{{ dataObj.quotation.quotation_validity ? dataObj.quotation.quotation_validity + '天' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_yjkgrq')">
								<text class="txt">预计开工日期</text>
								<view class="content">
									{{ dataObj.quotation.start_date ? dataObj.quotation.start_date : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_yjwgrq')">
								<text class="txt">预计完工日期</text>
								<view class="content">
									{{ dataObj.quotation.end_date ? dataObj.quotation.end_date : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_gqts')">
								<text class="txt">工期天数</text>
								<view class="content">
									{{ dataObj.quotation.duration_days ? dataObj.quotation.duration_days + '天' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_xmmj')">
								<text class="txt">项目面积</text>
								<view class="content">
									{{ dataObj.quotation.building_area ? dataObj.quotation.building_area + 'm²' : '--' }}
								</view>
							</view>
							<!-- 报价金额 -->
							<u-collapse accordion v-if="$fieldShowFunc('ys_bjje')" :border="false" value="bjje">
								<u-collapse-item
									title="报价金额"
									name="bjje"
									:isLink="$fieldShowFunc('ys_jczxf') || $fieldShowFunc('ys_zccgf') || $fieldShowFunc('ys_sj')"
									:value="dataObj.quotation.quotation_amount ? dataObj.quotation.quotation_amount + '元' : '--'"
								>
									<view class="item-child-box" v-if="$fieldShowFunc('ys_jczxf') || $fieldShowFunc('ys_zccgf') || $fieldShowFunc('ys_sj')">
										<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_jczxf')">
											<text class="txt">基础装修费</text>
											<view class="content">
												{{ dataObj.quotation.basic_decoration_fee ? dataObj.quotation.basic_decoration_fee + '元' : '--' }}
											</view>
										</view>
										<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_zccgf')">
											<text class="txt">主材采购费</text>
											<view class="content">
												{{ dataObj.quotation.material_costs ? dataObj.quotation.material_costs + '元' : '--' }}
											</view>
										</view>
										<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_sj')">
											<text class="txt">税金</text>
											<view class="content">
												{{
													dataObj.quotation.quotation_taxes
														? dataObj.quotation.quotation_taxes + '元'
														: dataObj.quotation.quotation_taxes == 0
														? '0元'
														: '--'
												}}
											</view>
										</view>
									</view>
								</u-collapse-item>
							</u-collapse>
							<block v-if="!$fieldShowFunc('ys_bjje')">
								<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_jczxf')">
									<text class="txt">基础装修费</text>
									<view class="content">
										{{ dataObj.quotation.basic_decoration_fee ? dataObj.quotation.basic_decoration_fee + '元' : '--' }}
									</view>
								</view>
								<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_zccgf')">
									<text class="txt">主材采购费</text>
									<view class="content">
										{{ dataObj.quotation.material_costs ? dataObj.quotation.material_costs + '元' : '--' }}
									</view>
								</view>
								<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_sj')">
									<text class="txt">税金</text>
									<view class="content">
										{{ dataObj.quotation.quotation_taxes ? dataObj.quotation.quotation_taxes + '元' : dataObj.quotation.quotation_taxes == 0 ? '0元' : '--' }}
									</view>
								</view>
							</block>
							<!-- 成本金额 -->
							<u-collapse accordion v-if="$fieldShowFunc('ys_cbje')" :border="false" value="cbje">
								<u-collapse-item
									title="成本金额"
									name="cbje"
									:isLink="$fieldShowFunc('ys_xccgcb') || $fieldShowFunc('ys_gscjcb') || $fieldShowFunc('ys_glcb')"
									:value="dataObj.quotation.cost_amount ? dataObj.quotation.cost_amount + '元' : '--'"
								>
									<view class="item-child-box" v-if="$fieldShowFunc('ys_xccgcb') || $fieldShowFunc('ys_gscjcb') || $fieldShowFunc('ys_glcb')">
										<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_xccgcb')">
											<text class="txt">现场采购成本</text>
											<view class="content">
												{{ dataObj.quotation.procurement_cost ? dataObj.quotation.procurement_cost + '元' : '--' }}
											</view>
										</view>
										<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_gscjcb')">
											<text class="txt">公司采集成本</text>
											<view class="content">
												{{ dataObj.quotation.centralized_procurement_cost ? dataObj.quotation.centralized_procurement_cost + '元' : '--' }}
											</view>
										</view>
										<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_glcb')">
											<text class="txt">管理成本</text>
											<view class="content">
												{{ dataObj.quotation.management_costs ? dataObj.quotation.management_costs + '元' : '--' }}
											</view>
										</view>
									</view>
								</u-collapse-item>
							</u-collapse>
							<block v-if="!$fieldShowFunc('ys_cbje')">
								<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_xccgcb')">
									<text class="txt">现场采购成本</text>
									<view class="content">
										{{ dataObj.quotation.procurement_cost ? dataObj.quotation.procurement_cost + '元' : '--' }}
									</view>
								</view>
								<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_gscjcb')">
									<text class="txt">公司采集成本</text>
									<view class="content">
										{{ dataObj.quotation.centralized_procurement_cost ? dataObj.quotation.centralized_procurement_cost + '元' : '--' }}
									</view>
								</view>
								<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_glcb')">
									<text class="txt">管理成本</text>
									<view class="content">
										{{ dataObj.quotation.management_costs ? dataObj.quotation.management_costs + '元' : '--' }}
									</view>
								</view>
							</block>

							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_lrje')">
								<text class="txt">利润金额</text>
								<view class="content">
									{{ dataObj.quotation.profit_amount ? dataObj.quotation.profit_amount + '元' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('ys_cblrl')">
								<text class="txt">成本利润率</text>
								<view class="content">
									{{ dataObj.quotation.profit_ratio ? dataObj.quotation.profit_ratio + '%' : '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="dataObj.quotation && $fieldShowFunc('ys_bjd')">
								<text class="txt">报价单</text>
								<view class="content flex ac flex">
									<image
										v-for="(file, idx) in dataObj.quotation.quotation_file"
										:key="idx"
										:src="$fileImgFunc(file)"
										mode="aspectFill"
										class="img-box"
										@click="previewFunc(file)"
									></image>
									<template v-if="!dataObj.quotation.quotation_file.length">--</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="dataObj.quotation && $fieldShowFunc('ys_cbd')">
								<text class="txt">工程量清单</text>
								<view class="content flex ac flex">
									<image
										v-for="(file, idx) in dataObj.quotation.cost_list_file"
										:key="idx"
										:src="$fileImgFunc(file)"
										mode="aspectFill"
										class="img-box"
										@click="previewFunc(file)"
									></image>
									<template v-if="!dataObj.quotation.cost_list_file.length">--</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="dataObj.quotation && $fieldShowFunc('ys_lrd')">
								<text class="txt">利润单</text>
								<view class="content flex ac flex">
									<image
										v-for="(file, idx) in dataObj.quotation.profit_statement_file"
										:key="idx"
										:src="$fileImgFunc(file)"
										mode="aspectFill"
										class="img-box"
										@click="previewFunc(file)"
									></image>
									<template v-if="!dataObj.quotation.profit_statement_file.length">--</template>
								</view>
							</view>
						</view>
					</template>
					<!-- 历史记录 -->
					<template v-if="tabIndex == 1">
						<view class="item-box">
							<u-empty v-if="!logList.length" marginTop="300rpx" icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png" text=" "></u-empty>
							<u-steps current="0" direction="column" dot activeColor="#3b75ff" inactiveColor="#3b75ff">
								<u-steps-item v-for="(item, index) in logList" :key="index">
									<template slot="desc">
										<view class="steps-title flex ac jb">
											<view class="steps-title-title">{{ item.updated_at }}</view>
											<view class="steps-title-user-data-box flex ac jc">
												<image class="avater-box" :src="item.handlers_image" mode="aspectFit"></image>
												<view class="user-name u-line-1">
													{{ item.handlers_name + '-' + item.handlers_position }}
												</view>
											</view>
										</view>
										<view class="steps-desc">
											<view class="steps-desc-title">
												{{ item.content }}
											</view>
											<template v-if="item.log_status == 230 || item.log_status == 240">
												<view class="steps-desc-box flex ac">
													<view class="steps-desc-box-title">审批意见</view>
													<view class="steps-desc-box-desc">{{ item.form_data.remark || '--' }}</view>
												</view>
											</template>
											<!-- 造价内容 -->
											<template v-if="item.log_status == 220">
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_yjkgrq')">
													<view class="steps-desc-box-title">预计开工日期</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.start_date || '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_yjwgrq')">
													<view class="steps-desc-box-title">预计完工日期</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.end_date || '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_gqts')">
													<view class="steps-desc-box-title">工期天数</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.duration_days ? item.form_data.duration_days + '天' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_xmmj')">
													<view class="steps-desc-box-title">建筑面积</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.building_area ? item.form_data.building_area + 'm²' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_bjje')">
													<view class="steps-desc-box-title">报价金额</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.quotation_amount ? item.form_data.quotation_amount + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_jczxf')">
													<view class="steps-desc-box-title">基础装修费</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.basic_decoration_fee ? item.form_data.basic_decoration_fee + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_zccgf')">
													<view class="steps-desc-box-title">主材采购费用</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.material_costs ? item.form_data.material_costs + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_sj')">
													<view class="steps-desc-box-title">报价税金</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.quotation_taxes ? item.form_data.quotation_taxes + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_cbje')">
													<view class="steps-desc-box-title">成本金额</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.cost_amount ? item.form_data.cost_amount + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_xccgcb')">
													<view class="steps-desc-box-title">现场采购成本</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.procurement_cost ? item.form_data.procurement_cost + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_gscjcb')">
													<view class="steps-desc-box-title">公司采集成本</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.centralized_procurement_cost ? item.form_data.centralized_procurement_cost + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_glcb')">
													<view class="steps-desc-box-title">管理成本</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.management_costs ? item.form_data.management_costs + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_lrje')">
													<view class="steps-desc-box-title">利润金额</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.profit_amount ? item.form_data.profit_amount + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('ys_cblrl')">
													<view class="steps-desc-box-title">利润率</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.profit_ratio ? item.form_data.profit_ratio + '%' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac">
													<view class="steps-desc-box-title">备注</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.remark || '--' }}
													</view>
												</view>
												<view class="steps-desc-box" v-if="$fieldShowFunc('ys_bjd')">
													<view class="steps-desc-box-title">报价单</view>
													<view class="steps-desc-box-desc flex ac flex-wrap">
														<image
															@click="previewFunc(file)"
															class="img-box"
															v-for="(file, fileIndex) in item.form_data.quotation_file"
															:key="fileIndex"
															:src="$fileImgFunc(file)"
														></image>
													</view>
												</view>
												<view class="steps-desc-box" v-if="$fieldShowFunc('ys_lrd')">
													<view class="steps-desc-box-title">利润单</view>
													<view class="steps-desc-box-desc flex ac flex-wrap">
														<image
															@click="previewFunc(file)"
															class="img-box"
															v-for="(file, fileIndex) in item.form_data.profit_statement_file"
															:key="fileIndex"
															:src="$fileImgFunc(file)"
														></image>
													</view>
												</view>
												<view class="steps-desc-box" v-if="$fieldShowFunc('ys_cbd')">
													<view class="steps-desc-box-title">工程量清单</view>
													<view class="steps-desc-box-desc flex ac flex-wrap">
														<image
															@click="previewFunc(file)"
															class="img-box"
															v-for="(file, fileIndex) in item.form_data.cost_list_file"
															:key="fileIndex"
															:src="$fileImgFunc(file)"
														></image>
													</view>
												</view>
											</template>
										</view>
									</template>
								</u-steps-item>
							</u-steps>
						</view>
					</template>
				</view>
				<view class="bottom-btn-box flex ac jb" slot="bottom">
					<view style="width: 100%">
						<judgeBtn
							v-if="!loading"
							info
							unborder
							:per_arr="per_arr"
							:btns="btns"
							:state="dataObj.status"
							:item="dataObj"
							@change="btnsChange"
							objectType="bj"
						></judgeBtn>
					</view>
				</view>
			</z-paging>
		</pageTxt>
		<!-- 文件预览 -->
		<preFileCom :fileObj="fileObj" @onFileSuccess="fileObj = ''"></preFileCom>

		<budgetManagement :value.sync="per_name" :oper_item="oper_item" @submit="handleSubmit"></budgetManagement>
	</view>
</template>

<script>
export default {
	provide() {
		return {
			providedData: this.btns
		};
	},
	data() {
		return {
			per_arr: [],
			btns: [
				{
					per_name: 'preSettlement_addZjy',
					state: 1070,
					name: '分配造价员'
				},
				{
					per_name: 'budget_shbjd',
					state: 1090,
					name: '报价单初审'
				},
				{
					per_name: 'preSettlement_reexamine',
					state: 1092,
					name: '报价单复审'
				},
				{
					per_name: 'preSettlement_editZjy',
					func: (item) => {
						if (item.cost_estimator_name) {
							return true;
						} else {
							return false;
						}
					},
					name: '更换造价员'
				}
			],
			// 操作相关
			oper_item: {},
			per_name: '',

			fileObj: '',
			loading: true,
			dataObj: '',
			logList: [],
			tabIndex: 0,
			tablist: [
				{
					name: '详情'
				},
				{
					name: '历史记录'
				}
			]
		};
	},
	onLoad(option) {
		this.getBudgetDetails(option.id);

		// 获取权限
		this.$Api
			.getHtmlAuthority({
				path: '/budgetManagement'
			})
			.then((res) => {
				console.log(res, 'getHtmlAuthority');
				if (res.code == 200) {
					this.per_arr = res.data.permission;
				}
			});
	},
	methods: {
		onRefresh() {
			this.getBudgetDetails(this.dataObj.id);
			this.$refs.paging.complete();
		},
		tabClickFunc(e) {
			this.tabIndex = e.index;
		},
		// 详情
		getBudgetDetails(project_id) {
			this.loading = true;
			this.$Apipc
				.getBudgetDetails({
					project_id
				})
				.then((res) => {
					console.log(res, '预算详情');
					this.loading = false;
					if (res.code == 200) {
						if (Array.isArray(res.data.quotation)) {
							res.data.quotation = '';
						}
						res.data.log_list.forEach((item) => {
							item.form_data = JSON.parse(item.form_data);
						});
						this.dataObj = res.data;
						this.logList = res.data.log_list;
					}
				});
		},
		// 预览
		previewFunc(item) {
			this.fileObj = item;
		},

		// 操作按钮触发点击
		btnsChange(e) {
			console.log(e, 'xxxsww');
			this.oper_item = e.item;
			switch (e.per_name) {
				// 更换造价员
				case 'preSettlement_editZjy':
					this.per_name = e.per_name;
					break;
				// 分配造价员
				case 'preSettlement_addZjy':
					this.per_name = e.per_name;
					break;
				// 审核
				default:
					this.per_name = 'preSettlement_sh';
					break;
			}
		},

		handleSubmit(type) {
			this.onRefresh();
		},
		// 去详情项目
		navToProjectFunc() {
			uni.navigateTo({
				url: '/pagesB/projectDetail/projectDetail?id=' + this.dataObj.id
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
